#!/usr/bin/python
# -*- coding: utf-8 -*-

import re

cat = []
father = []
for i in range(1, 3):
	cat.append(open('/home/chaojiansong/videobook/notinsvn/cat' + str(i), 'r'))
	father.append(open('/home/chaojiansong/videobook/notinsvn/father' + str(i), 'r'))

up_cat = [{}, {}]

for i in range(0, 2):
    for line in cat[i]:
    	line2 = father[i].readline()
    	up_cat[i][line.rstrip()] = line2.rstrip()

titles = open('/home/chaojiansong/videobook/notinsvn/open_cats', 'r')
out = open('/home/chaojiansong/videobook/notinsvn/baike_tree', 'w')
title = ''
cur_cat = ''
for line in titles:
    m = re.match('title: (.*)', line)
    if m:
    	title = m.group(1)
        out.write('title: ' + title + '\n')
    else:
        m = re.match('cat: (.*)', line)
        cur_cat = m.group(1)
        out.write('cat2: ' + cur_cat + '\n')
        if up_cat[1].has_key(cur_cat):
            out.write('cat1: ' + up_cat[1][cur_cat] + '\n')
            out.write('cat0: ' + up_cat[0][up_cat[1][cur_cat]] + '\n')
        else:
            out.write('cat1: ' + '\n' + 'cat0: ' + '\n')

out.close()
titles.close()
for i in range(0, 2):
	cat[i].close()
	father[i].close()

